package com.alphawavesgames.engine.rendering;

import java.util.ArrayList;

/**
 *
 * @author Duncan
 */
public class VertexPos3Tex2
{
    //the vertex data. Position float3 and tex coords float2.
    public float[] m_position = new float[3];
    public float[] m_texCoords = new float[2];


    //todo - make a base class method and override?
    public static RenderHWInterface.VertexBuffer createVBForVertexType( RenderHWInterface renderHWI, int numElements )
    {
        RenderHWInterface.VertexBuffer vertexBuffer = renderHWI.createVertexBuffer();

        ArrayList< ElementStreamFloat > streamArray = new ArrayList< ElementStreamFloat >();
        //create a 3 float stream for the position
        ElementStreamFloat posStream = new ElementStreamFloat( 3, numElements, ElementStream.StreamType.POSITION );
        //vertexBuffer.addElementStream( posStream );
        streamArray.add( posStream );

        //create  a 2 float stream for the tex coords
        ElementStreamFloat texStream = new ElementStreamFloat( 2, numElements, ElementStream.StreamType.TEXCOORD );
        //vertexBuffer.addElementStream( texStream );
        streamArray.add( texStream );

        vertexBuffer.createFromElementStreams( streamArray );

        return vertexBuffer;
    }

    //write this vertex's data to an element in the vertex buffer.
    //what to do about making sure vertBuffer is the correctly set up
    //for this vertex type? It may not have the streams we need available.
    public void writeToVB( int index, RenderHWInterface.VertexBuffer vertBuffer )
    {
        ElementStreamFloat posStream = vertBuffer.getStream( 0 );
        ElementStreamFloat texStream = vertBuffer.getStream( 1 );

        posStream.setBlock( index, m_position );

        texStream.setBlock( index, m_texCoords );
    }

    //a class used to write vertices to the streams used by the vertex buffer
    /*
     public class VertexStreamWriter
    {
        protected ElementStreamFloat m_posStream;
        protected ElementStreamFloat m_texStream;
        
        protected VertexBuffer m_vertexBuffer;
        
        public VertexStreamWriter( int numElements )
        {
            m_vertexBuffer = new VertexBuffer();

            //create a 3 float stream for the position
            m_posStream = new ElementStreamFloat( numElements * 3 );
            m_vertexBuffer.addElementStream( m_posStream );

            //create  a 2 float stream for the tex coords
            m_texStream = new ElementStreamFloat( numElements * 2 );
            m_vertexBuffer.addElementStream( m_texStream );
        }

        public VertexBuffer getVertexBuffer()
        {
            return m_vertexBuffer;
        }

//        public static VertexStreamWriter createWriter( int numElements )
//        {
//            VertexStreamWriter writer = new VertexStreamWriter( numElements );
//            return writer;
//        }

    }*/

    

}
